<template>
  <div>父级</div>
  <div>子组件传父组件的值： {{nameStr.name}}</div>
  <br/>
  <!-- <wwaterFallVue :title="name"></wwaterFallVue> -->
  <waterFallVue ref="waterFall" @on-click="getName"></waterFallVue>
</template>

<script setup lang="ts">
import { ref, onMounted, nextTick } from "vue"
import waterFallVue from "./components/water-fall02.vue"

// 获取实例，读取子组件的属性和方法
/* 
  实例作用域要最大，必须放在最外层，如果放在onMounted里面就相当于重新申明了 
  注意这儿的typeof里面放的是组件名字(waterFallVue)不是ref的名字 ref的名字对应开头的变量名(waterFall)
*/
const waterFall = ref<InstanceType<typeof waterFallVue>>()

// 
onMounted(() => {
  console.log("创建完成：onMounted")
  console.log(waterFall.value)  // undefined
  console.log(waterFall.value.name, waterFall.value.open())
})

const nameStr = ref({name: "暂无"})

const getName = (name:string) => {
  console.log(name)
  nameStr.value.name = name
}

</script>

<style lang="scss">
  
</style>